cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        m_Hero:cc.Node,
        m_roll:cc.Button,
        
    },

    // use this for initialization
    onLoad: function () {
        this.m_roll.node.on(cc.Node.EventType.TOUCH_START,this.roll,this);
        this.m_roll.node.on(cc.Node.EventType.TOUCH_END,this.down,this);
        this.m_roll.node.on(cc.Node.EventType.TOUCH_CANCEL,this.down,this);
        this.m_Hero.getComponent(cc.Animation).play("Run");
    },
    
    roll:function(){
        this.animation = this.m_Hero.getComponent(cc.Animation);
        console.log(this.animation.name);
        if(this.animation.currentClip.name != "Run"){
            return;
        }
         this.m_Hero.setPosition(-233,-158);
        this.animation.play('roll');
    },
    
    down:function(){
        console.log("down");
        this.animation = this.m_Hero.getComponent(cc.Animation);
       
        if(this.animation.currentClip.name != "roll"){
            return;
        }
        
        this.m_Hero.setPosition(-233,-143);
        this.animation.play('Run');
    },
    
    // 起跳结束回调
    callBackDownOver : function(){
        console.log("callBackDownOver");
        var tmp = this.getComponent(cc.Animation);
        tmp.play('Run');
    },
    onChangeAnimation:function(e,data){
        console.log(data);
        this.animation = this.m_Hero.getComponent(cc.Animation);
        //  如果跳起
        if(data == 'jump' && this.animation.currentClip.name == "Run"){
            var up = cc.moveTo(0.5,-233,90).easing(cc.easeCubicActionOut());
            var down = cc.moveTo(0.5,-233,-143.6).easing(cc.easeCubicActionIn());
            var conback = cc.callFunc(this.callBackDownOver,this.m_Hero);
            var seq = cc.sequence(up,down,conback);
            this.m_Hero.runAction(seq);
            this.animation.play(data);     
        }
    },
    
    
});
